package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.urea.system.domain.vo.OrderDto;
import com.urea.system.domain.vo.OrderStatisticsVo;
import com.urea.system.domain.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.Order;
import com.urea.system.service.IOrderService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单信息")
public class OrderController extends BaseController
{
    @Autowired
    private IOrderService orderService;

    /**
     * 查询订单列表
     */
//    @PreAuthorize("@ss.hasPermi('order:list')")
    @GetMapping("/list")
    @ApiOperation("订单信息列表")
    public TableDataInfo list(Order order)
    {
        startPage();
        List<OrderVo> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * pc端订单统计列表
     * @param vo 条件
     * @return 结果
     */
    @GetMapping("/statisticsList")
    @ApiOperation("pc订单统计列表/代理商统计列表共用")
    public TableDataInfo statisticsList(OrderVo vo)
    {
        startPage();
        List<OrderStatisticsVo> list = orderService.statisticsList(vo);
        return getDataTable(list);
    }

    @GetMapping("/statistics")
    @ApiOperation("pc订单统计数据")
    public AjaxResult statistics(OrderVo vo)
    {
        return success(orderService.statistics(vo));
    }

    /**
     * 导出pc统计订单列表
     */
    @Log(title = "导出pc统计订单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/statisticsListExport")
    @ApiOperation("导出pc统计订单列表")
    public void statisticsListExport(HttpServletResponse response, OrderVo vo)
    {
        List<OrderStatisticsVo> list = orderService.statisticsList(vo);
        ExcelUtil<OrderStatisticsVo> util = new ExcelUtil<>(OrderStatisticsVo.class);
        util.exportExcel(response, list, "订单统计数据");
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Order order)
    {
        List<OrderVo> list = orderService.selectOrderList(order);
        ExcelUtil<OrderVo> util = new ExcelUtil<>(OrderVo.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('order:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取订单详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderService.selectOrderById(id));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Order order)
    {
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Order order)
    {
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderService.deleteOrderByIds(ids));
    }



    @GetMapping("/queryOrderList")
    @ApiOperation("pc端订单管理列表")
    public TableDataInfo queryOrderList( OrderDto dto){
        startPage();
        List<OrderDto> list = orderService.queryOrderList(dto);
        return getDataTable(list);
    }

    @GetMapping("/countOrders")
    @ApiOperation("统计订单金额")
    public AjaxResult countOrders( OrderDto dto){
        return success(orderService.countOrders(dto));
    }

    @Log(title = "导出pc统计订单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/orderListExport")
    @ApiOperation("pc端订单管理列表导出")
    public void orderListExport(HttpServletResponse response, OrderDto vo)
    {
        List<OrderDto> list = orderService.queryOrderList(vo);
        ExcelUtil<OrderDto> util = new ExcelUtil<>(OrderDto.class);
        util.exportExcel(response, list, "订单列表");
    }

    @Log(title = "发送微信公众号消息", businessType = BusinessType.EXPORT)
    @GetMapping("/msg")
    @ApiOperation("发送微信公众号消息")
    public void orderMsg(String orderNo)
    {
        orderService.sendOrderMsg(orderNo);
    }
}
